//思路: 
//1.求最短距离 --- 可以反证法证明两个序列顺序排列时距离是最短的
//2.求最小交换次数 --- 原序列不好看, 转化成下标的交换次数 --- 本质就是求逆序对的个数
//如何得到交换后的下标数组? 
//将两个序列的值和下标绑定, 进行排序即可

#include <iostream>
#include <algorithm>
using namespace std;
#define lowbit(x) (x & -x)
const int N = 1e5 + 10;
typedef long long ll;
ll s[N]; //树状数组, 维护的是区间内元素的个数
int c[N];
const int mod = 1e8 - 3;

int n;
struct node
{
    ll x, id;
}a[N], b[N];

bool cmp(node& x, node& y)
{
    return x.x < y.x; //按值排序
}

void modify(int x, ll k)
{
    for(int i = x; i <= n; i += lowbit(i)) s[i] += k;
}

//[1, x]区间元素的个数
ll query(int x)
{
    ll sum = 0;
    for(int i = x; i; i -= lowbit(i)) sum += s[i];
    return sum;
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].x;
        a[i].id = i;
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> b[i].x;
        b[i].id = i;
    }
    sort(a+1, a+1+n, cmp);
    sort(b+1, b+1+n, cmp);
    for(int i = 1; i <= n; i++) c[a[i].id] = b[i].id;
    
    ll ret = 0;
    for(int i = 1; i <= n; i++)
    {
        ret += query(n) - query(c[i]);
        modify(c[i], 1);
    }
    cout << ret % mod << endl;
    return 0;
}